package com.ghck.server.bkcontroller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.ghck.server.model.Users;
import com.ghck.server.model.query.UsersQuery;
import com.ghck.server.service.UsersService;
import com.ghck.shop.model.Page;


@Controller
@RequestMapping(value="/system/user")
public class AdminUserController {
	
	@Autowired
	private UsersService usersService;
	
	@RequestMapping(value="/list")
	public String main(UsersQuery usersQuery,
			@RequestParam(defaultValue = "1") Integer currentPage,
			@RequestParam(defaultValue = "10") Integer pageSize,
            HttpServletRequest request){
		int start = 0;
		if(currentPage > 0 ){
			start = ((currentPage-1)*pageSize);
		}
		Page<Users> page = new Page<Users>(currentPage);
		page.setPageSize(pageSize);
		usersQuery.setStart(start);
		usersQuery.setLimit(pageSize);
		List<Users> list = usersService.findUsersByQuery(usersQuery);
		page.setResultRows(list);
		page.setTotalRow(usersService.countUsersByQuery(usersQuery));
		request.setAttribute("page", page);
		return "back/user/list";
	}
}
